//
//  HearNavigationController.m
//  Hear
//
//  Created by mac on 2017/3/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HearNavigationController.h"
#import "UIDevice+YYAdd.h"
@interface HearNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation HearNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.navigationBar.backgroundColor = NavTinColor;
    
    if ([UIDevice systemVersion] >= 11){
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
        self.navigationBar.tintColor = [UIColor whiteColor];
        
//        UIImage *backButtonImage = [[UIImage imageNamed:@"Back-Arrow"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//        self.navigationBar.backIndicatorImage = backButtonImage;
//        self.navigationBar.backIndicatorTransitionMaskImage = backButtonImage;
    }
    
    self.interactivePopGestureRecognizer.delegate = self;

}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (self.viewControllers.count <= 1 ) {
        return NO;
    }
    return YES;
}

// 允许同时响应多个手势
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:
(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldBeRequiredToFailByGestureRecognizer:
(UIGestureRecognizer *)otherGestureRecognizer {
    return [gestureRecognizer isKindOfClass:
            UIScreenEdgePanGestureRecognizer.class];
}




+(void)initialize
{
    [self setupNavBarTheme];
}

/**
 *  设置导航栏主题
 */
+ (void)setupNavBarTheme
{
    
    //设置Nav的背景色和title色
    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    
//        [navigationBarAppearance setTintColor:textColorBlackNormal];//返回按钮的箭头颜色
    
    NSDictionary *textAttributes  = @{
                                      NSFontAttributeName: CustomUIFont(17),
                                      NSForegroundColorAttributeName:[UIColor whiteColor]
                                      
                                      };
    
    [navigationBarAppearance setBackgroundColor:NavTinColor];
    
    [navigationBarAppearance setBarTintColor:NavTinColor];
    
    [navigationBarAppearance setTitleTextAttributes:textAttributes];
    

    
    if ([UIDevice systemVersion] >= 11){
        
    }else{
        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
        UIImage *backImageView = [UIImage imageNamed:@"Back-Arrow"];
        backImageView = [backImageView resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0) resizingMode:UIImageResizingModeStretch];
        [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backImageView forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    }

}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
    
    // 修改tabBra的frame
    CGRect frame = self.tabBarController.tabBar.frame;
    frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
    self.tabBarController.tabBar.frame = frame;
}


-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
